#include<func.h>
int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,2)
    DIR* dir;
    dir=opendir(argv[1]);
    ERROR_CHECK(dir,NULL,"opendir")
    struct dirent *pdir;
    struct stat buf;
    int ret;
    while(pdir=readdir(dir))
    {
        ret=stat(pdir->d_name,&buf);
        ERROR_CHECK(ret,-1,"stat");
        char buf_time[1024]={0};
        char buf_tmp[1024]={0};
        int flag=0;
        strcpy(buf_time,ctime(&buf.st_mtime)+4);
         for(int i=0;i<strlen(buf_time);i++)//截断时间
    {
       
        if(buf_time[i]==':')
        {
            if(flag==0)
            {
                flag=1;
                buf_tmp[i]=buf_time[i];
            }
            else
            {break;}
        }
        else
        {buf_tmp[i]=buf_time[i];}
    }
    char mode[11]={0};
    char chmod[3]={'x','r','w',};
    memset(mode,'-',sizeof(mode)-1);
    
    long temp=buf.st_mode;//八进制
    if((temp&32768)==0)
    {
        mode[0]='d';
    }
    for(int i=1;i<10;i++)
    {
        if((temp&(1<<(9-i)))!=0)
        {
            mode[i]=chmod[i%3];
        }
    }
    printf("%s %3ld %s %s %6ld %s %s\n",mode,buf.st_nlink,getpwuid(buf.st_uid)->pw_name,\
    getgrgid(buf.st_gid)->gr_name,buf.st_size,buf_tmp,pdir->d_name);

    }
}